package com.yoso.shop.infrastructure.config;

import lombok.Data;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author shizejin
 * @date 2022/2/23
 * @description:
 */
@Configuration
@Data
public class InitConfig {
    /**
     * 服务端口
     */
    @Value("${server.port}")
    private String port;
    /**
     * 静态资源根路径(真实路径)
     */
    @Value("${shop.static-file-folder}")
    private String staticFolderPath;
    /**
     * 静态资源映射路径(访问路径)
     */
    @Value("static")
    private String staticRequestPath;

    /**
     * @return 本机ipv4的地址
     */
    @SneakyThrows
    @Bean
    public String getIpv4() {
        String ipv4 = "localhost";
/*        Enumeration allNetInterfaces = NetworkInterface.getNetworkInterfaces();
        InetAddress ip = null;
        while (allNetInterfaces.hasMoreElements()) {
            NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();
            Enumeration addresses = netInterface.getInetAddresses();
            while (addresses.hasMoreElements()) {
                ip = (InetAddress) addresses.nextElement();
                if (ip instanceof Inet4Address) {
                    ipv4 = ip.getHostAddress();
                }
            }
        }*/
        return ipv4;
    }
}
